//
//  TwoTableViewCell.m
//  News
//
//  Created by xalo on 16/3/1.
//  Copyright © 2016年 News. All rights reserved.
//

#import "TwoTableViewCell.h"
#import "PicListModel.h"
#import "UIImageView+WebCache.h"
#import <Reachability.h>
@implementation TwoTableViewCell

-(void)setPicMod:(PicListModel *)picMod {
    
    
  
    
    _picMod =picMod ;
    _title.text = picMod.title ;
    _subtitle.text = picMod.intro ;
    
    extern BOOL isWiFiMode;
    Reachability *ablity = [Reachability reachabilityForInternetConnection];
    if (([ablity isReachableViaWiFi])||([ablity isReachable] && !isWiFiMode)||(![ablity  isReachable])) {
        
        [self.image1 sd_setImageWithURL:[NSURL URLWithString:picMod.list[0][@"kpic"]]placeholderImage:[UIImage imageNamed:@"background"]];
         [self.image2 sd_setImageWithURL:[NSURL URLWithString:picMod.list[1][@"kpic"]]placeholderImage:[UIImage imageNamed:@"background"]];
        
        }
    
    CGFloat height = [TwoTableViewCell cellOfheightWITString:picMod.intro];
     if (height > 20) {
    CGRect frame = self.subtitle.frame;
    frame.size.height =height;
    self.subtitle.frame =frame;
     }
    
       _picMod.cellHeight = self.image1.frame.size.height +self.title.frame.size.height + 20 +height;
    
}

+(CGFloat)cellOfheightWITString:(NSString *)string
{
    
    NSDictionary *dic =[NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:12] forKey:NSFontAttributeName];
    
    CGFloat weith = [UIScreen mainScreen].bounds.size.width ;
    
    CGFloat cellWith = weith - 10;
    CGRect bound = [string boundingRectWithSize:CGSizeMake(cellWith, 2000) options:(NSStringDrawingUsesLineFragmentOrigin)attributes:dic context:nil];
    
    return bound.size.height;
}



@end
